const http = require('http')
const server = http.createServer()
const controller = require('./Controller')
const Controller = new controller()

server.on('request', async (req, res) => {
  res.setHeader('Access-Control-Allow-Origin', '*')
  res.setHeader('Access-Control-Allow-Headers', '*')

  if (req.method == 'OPTIONS') {
    res.status = 200
    res.end()
    return
  }
  if (req.url === '/') {
    Controller.handleFormData(req, res)
  }
  if (req.url === '/back') {
    console.log('/bb')
    res.end('back!')
    // Controller.handleFormData(req, res);
  }
  if (req.url === '/back/abc') {
    console.log('/bbccc')
    res.end('backccc!')
    // Controller.handleFormData(req, res);
  }
  if (req.url === '/verify') {
    Controller.handleVerifyUpload(req, res)
  }
  if (req.url === '/merge') {
    Controller.handleMerge(req, res)
  }
})

server.listen('4567', () => console.log('http://localhost:4567'))
